package com.company.nuwa.common.utils;

import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * <p>feign接口platformId处理</p>
 *
 * @author lili
 * @version 1.0: ZkPlatformUtils
 * @date 2023/11/8 09:53
 */
@Slf4j
public class ZkPlatformUtils {

    private static final InheritableThreadLocal<Long> PLATFORM_ID_THREAD_LOCAL = new InheritableThreadLocal<>();

    public static void removePlatformId() {
        PLATFORM_ID_THREAD_LOCAL.remove();
    }

    public static Long getPlatformId() {
        Long platformId = PLATFORM_ID_THREAD_LOCAL.get();
        // if null set default 0
        platformId = ObjectUtil.defaultIfNull(platformId, 0L);
        log.info("get platformId:{}", platformId);
        return platformId;
    }

    public static void setPlatformId(Long platformId) {
        log.info("set platformId:{}", platformId);
        PLATFORM_ID_THREAD_LOCAL.set(platformId);
    }

    public static void setPlatformId(String platformId) {
        log.info("set platformId:{}", platformId);
        PLATFORM_ID_THREAD_LOCAL.set(Long.valueOf(platformId));

    }
}
